﻿using System;
using DevExpress.XtraEditors;

namespace PropertyManagement.Client.WinFormClient.Forms.Utilies
{
    public class ExceptionUtil
    {
        public static void HandleException(Exception ex)
        {
            if (ex is System.ServiceModel.FaultException<System.ServiceModel.ExceptionDetail>)
            {
                var newEx = ex as System.ServiceModel.FaultException<System.ServiceModel.ExceptionDetail>;
                if (newEx.Detail.InnerException==null)
                {
                    XtraMessageBox.Show("操作失败！" + ex.Message);
                    return;
                }
                if (newEx.Detail.InnerException.Message.Contains("由于将在索引、 主关键字、或关系中创建重复的值"))
                    XtraMessageBox.Show("名称重复，请修改为其他名称");
                else
                {
                    XtraMessageBox.Show("操作失败！" + newEx.Detail.InnerException.Message);
                }
            }
            else
                XtraMessageBox.Show("操作失败！" + ex.Message);
        }
    }
}
